package com.xqb.modules.controller.order;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.OrdCart;
import com.xqb.modules.service.IOrdCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 购物车条目信息Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/order/cart")
public class OrdCartController extends BaseController
{
    @Autowired
    private IOrdCartService ordCartService;

    /**
     * 查询购物车条目信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdCart ordCart)
    {
        startPage();
        List<OrdCart> list = ordCartService.selectOrdCartList(ordCart);
        return getDataTable(list);
    }

    /**
     * 导出购物车条目信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:cart:export')")
    @Log(title = "购物车条目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrdCart ordCart)
    {
        List<OrdCart> list = ordCartService.selectOrdCartList(ordCart);
        ExcelUtil<OrdCart> util = new ExcelUtil<OrdCart>(OrdCart.class);
        util.exportExcel(response, list, "购物车条目信息数据");
    }

    /**
     * 获取购物车条目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:cart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ordCartService.selectOrdCartById(id));
    }

    /**
     * 新增购物车条目信息
     */
    @PreAuthorize("@ss.hasPermi('order:cart:add')")
    @Log(title = "购物车条目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdCart ordCart)
    {
        return toAjax(ordCartService.insertOrdCart(ordCart));
    }

    /**
     * 修改购物车条目信息
     */
    @PreAuthorize("@ss.hasPermi('order:cart:edit')")
    @Log(title = "购物车条目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdCart ordCart)
    {
        return toAjax(ordCartService.updateOrdCart(ordCart));
    }

    /**
     * 删除购物车条目信息
     */
    @PreAuthorize("@ss.hasPermi('order:cart:remove')")
    @Log(title = "购物车条目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ordCartService.deleteOrdCartByIds(ids));
    }
}
